package com.zaofan.dao;

import java.sql.SQLException;
import java.util.Collections;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.zaofan.bean.OrderDetail;
import com.zaofan.dao.base.DaoSupportImpl;

public class OrderDetailDao extends DaoSupportImpl<OrderDetail> {
	
	private static Logger logger = LoggerFactory.getLogger(OrderDetailDao.class);
	
	
	public List<OrderDetail> getOrderDetailsWithSendDate(int parentOrderId) {
		try {
			String sql = "select orderdetail.*, orderinfo.sendDate from orderdetail join orderinfo on orderdetail.orderId = orderinfo.id where orderdetail.parentOrderId = " + parentOrderId;
			logger.info(sql);
			QueryRunner runner = new QueryRunner(getDataSource());
			return runner.query(sql, new BeanListHandler<>(OrderDetail.class));
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return Collections.emptyList();

	} 

}
